<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module Fiddle - fiddle: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#module-Fiddle-label-Description">Description</a>
    <li><a href="#module-Fiddle-label-Example">Example</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-dlopen">::dlopen</a>
    <li ><a href="#method-c-dlunwrap">::dlunwrap</a>
    <li ><a href="#method-c-dlwrap">::dlwrap</a>
    <li ><a href="#method-c-free">::free</a>
    <li ><a href="#method-c-last_error">::last_error</a>
    <li ><a href="#method-c-last_error-3D">::last_error=</a>
    <li ><a href="#method-c-malloc">::malloc</a>
    <li ><a href="#method-c-realloc">::realloc</a>
    <li ><a href="#method-c-win32_last_error">::win32_last_error</a>
    <li ><a href="#method-c-win32_last_error-3D">::win32_last_error=</a>
    <li ><a href="#method-c-win32_last_socket_error">::win32_last_socket_error</a>
    <li ><a href="#method-c-win32_last_socket_error-3D">::win32_last_socket_error=</a>
    <li ><a href="#method-i-dlopen">#dlopen</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-Fiddle">
    <h1 id="module-Fiddle" class="module">
      module Fiddle
    </h1>

    <section class="description">
    
<p>A libffi wrapper for Ruby.</p>

<h2 id="module-Fiddle-label-Description">Description<span><a href="#module-Fiddle-label-Description">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p><a href="Fiddle.html"><code>Fiddle</code></a> is an extension to translate a foreign function interface (FFI) with ruby.</p>

<p>It wraps <a href="http://sourceware.org/libffi/">libffi</a>, a popular C library which provides a portable interface that allows code written in one language to call code written in another language.</p>

<h2 id="module-Fiddle-label-Example">Example<span><a href="#module-Fiddle-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Here we will use <a href="Fiddle/Function.html"><code>Fiddle::Function</code></a> to wrap <a href="http://linux.die.net/man/3/floor">floor(3) from libm</a></p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;fiddle&#39;</span>

<span class="ruby-identifier">libm</span> = <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">dlopen</span>(<span class="ruby-string">&#39;/lib/libm.so.6&#39;</span>)

<span class="ruby-identifier">floor</span> = <span class="ruby-constant">Fiddle</span><span class="ruby-operator">::</span><span class="ruby-constant">Function</span>.<span class="ruby-identifier">new</span>(
  <span class="ruby-identifier">libm</span>[<span class="ruby-string">&#39;floor&#39;</span>],
  [<span class="ruby-constant">Fiddle</span><span class="ruby-operator">::</span><span class="ruby-constant">TYPE_DOUBLE</span>],
  <span class="ruby-constant">Fiddle</span><span class="ruby-operator">::</span><span class="ruby-constant">TYPE_DOUBLE</span>
)

<span class="ruby-identifier">puts</span> <span class="ruby-identifier">floor</span>.<span class="ruby-identifier">call</span>(<span class="ruby-value">3.14159</span>) <span class="ruby-comment">#=&gt; 3.0</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="ALIGN_CHAR">ALIGN_CHAR
          <dd><p><a href="Fiddle.html#ALIGN_CHAR"><code>ALIGN_CHAR</code></a></p>

<p>The alignment size of a char</p>
          <dt id="ALIGN_DOUBLE">ALIGN_DOUBLE
          <dd><p><a href="Fiddle.html#ALIGN_DOUBLE"><code>ALIGN_DOUBLE</code></a></p>

<p>The alignment size of a double</p>
          <dt id="ALIGN_FLOAT">ALIGN_FLOAT
          <dd><p><a href="Fiddle.html#ALIGN_FLOAT"><code>ALIGN_FLOAT</code></a></p>

<p>The alignment size of a float</p>
          <dt id="ALIGN_INT">ALIGN_INT
          <dd><p><a href="Fiddle.html#ALIGN_INT"><code>ALIGN_INT</code></a></p>

<p>The alignment size of an int</p>
          <dt id="ALIGN_INT16_T">ALIGN_INT16_T
          <dd><p><a href="Fiddle.html#ALIGN_INT16_T"><code>ALIGN_INT16_T</code></a></p>

<p>The alignment size of a int16_t</p>
          <dt id="ALIGN_INT32_T">ALIGN_INT32_T
          <dd><p><a href="Fiddle.html#ALIGN_INT32_T"><code>ALIGN_INT32_T</code></a></p>

<p>The alignment size of a int32_t</p>
          <dt id="ALIGN_INT64_T">ALIGN_INT64_T
          <dd><p><a href="Fiddle.html#ALIGN_INT64_T"><code>ALIGN_INT64_T</code></a></p>

<p>The alignment size of a int64_t</p>
          <dt id="ALIGN_INT8_T">ALIGN_INT8_T
          <dd><p><a href="Fiddle.html#ALIGN_INT8_T"><code>ALIGN_INT8_T</code></a></p>

<p>The alignment size of a int8_t</p>
          <dt id="ALIGN_INTPTR_T">ALIGN_INTPTR_T
          <dd><p><a href="Fiddle.html#ALIGN_INTPTR_T"><code>ALIGN_INTPTR_T</code></a></p>

<p>The alignment size of a intptr_t</p>
          <dt id="ALIGN_LONG">ALIGN_LONG
          <dd><p><a href="Fiddle.html#ALIGN_LONG"><code>ALIGN_LONG</code></a></p>

<p>The alignment size of a long</p>
          <dt id="ALIGN_LONG_LONG">ALIGN_LONG_LONG
          <dd><p><a href="Fiddle.html#ALIGN_LONG_LONG"><code>ALIGN_LONG_LONG</code></a></p>

<p>The alignment size of a long long</p>
          <dt id="ALIGN_PTRDIFF_T">ALIGN_PTRDIFF_T
          <dd><p><a href="Fiddle.html#ALIGN_PTRDIFF_T"><code>ALIGN_PTRDIFF_T</code></a></p>

<p>The alignment size of a ptrdiff_t</p>
          <dt id="ALIGN_SHORT">ALIGN_SHORT
          <dd><p><a href="Fiddle.html#ALIGN_SHORT"><code>ALIGN_SHORT</code></a></p>

<p>The alignment size of a short</p>
          <dt id="ALIGN_SIZE_T">ALIGN_SIZE_T
          <dd><p><a href="Fiddle.html#ALIGN_SIZE_T"><code>ALIGN_SIZE_T</code></a></p>

<p>The alignment size of a size_t</p>
          <dt id="ALIGN_SSIZE_T">ALIGN_SSIZE_T
          <dd><p><a href="Fiddle.html#ALIGN_SSIZE_T"><code>ALIGN_SSIZE_T</code></a></p>

<p>The alignment size of a ssize_t</p>
          <dt id="ALIGN_UINTPTR_T">ALIGN_UINTPTR_T
          <dd><p><a href="Fiddle.html#ALIGN_UINTPTR_T"><code>ALIGN_UINTPTR_T</code></a></p>

<p>The alignment size of a uintptr_t</p>
          <dt id="ALIGN_VOIDP">ALIGN_VOIDP
          <dd><p><a href="Fiddle.html#ALIGN_VOIDP"><code>ALIGN_VOIDP</code></a></p>

<p>The alignment size of a void*</p>
          <dt id="BUILD_RUBY_PLATFORM">BUILD_RUBY_PLATFORM
          <dd><p><a href="Fiddle.html#BUILD_RUBY_PLATFORM"><code>BUILD_RUBY_PLATFORM</code></a></p>

<p>Platform built against (i.e. “x86_64-linux”, etc.)</p>

<p>See also RUBY_PLATFORM</p>
          <dt id="Qfalse">Qfalse
          <dd><p><a href="Fiddle.html#Qfalse"><code>Qfalse</code></a></p>

<p>The value of <a href="Fiddle.html#Qfalse"><code>Qfalse</code></a></p>
          <dt id="Qnil">Qnil
          <dd><p><a href="Fiddle.html#Qnil"><code>Qnil</code></a></p>

<p>The value of <a href="Fiddle.html#Qnil"><code>Qnil</code></a></p>
          <dt id="Qtrue">Qtrue
          <dd><p><a href="Fiddle.html#Qtrue"><code>Qtrue</code></a></p>

<p>The value of <a href="Fiddle.html#Qtrue"><code>Qtrue</code></a></p>
          <dt id="Qundef">Qundef
          <dd><p><a href="Fiddle.html#Qundef"><code>Qundef</code></a></p>

<p>The value of <a href="Fiddle.html#Qundef"><code>Qundef</code></a></p>
          <dt id="RUBY_FREE">RUBY_FREE
          <dd><p><a href="Fiddle.html#RUBY_FREE"><code>RUBY_FREE</code></a></p>

<p>Address of the ruby_xfree() function</p>
          <dt id="SIZEOF_BOOL">SIZEOF_BOOL
          <dd><p><a href="Fiddle.html#SIZEOF_BOOL"><code>SIZEOF_BOOL</code></a></p>

<p>size of a bool</p>
          <dt id="SIZEOF_CHAR">SIZEOF_CHAR
          <dd><p><a href="Fiddle.html#SIZEOF_CHAR"><code>SIZEOF_CHAR</code></a></p>

<p>size of a char</p>
          <dt id="SIZEOF_CONST_STRING">SIZEOF_CONST_STRING
          <dd><p><a href="Fiddle.html#SIZEOF_CONST_STRING"><code>SIZEOF_CONST_STRING</code></a></p>

<p>size of a const char*</p>
          <dt id="SIZEOF_DOUBLE">SIZEOF_DOUBLE
          <dd><p><a href="Fiddle.html#SIZEOF_DOUBLE"><code>SIZEOF_DOUBLE</code></a></p>

<p>size of a double</p>
          <dt id="SIZEOF_FLOAT">SIZEOF_FLOAT
          <dd><p><a href="Fiddle.html#SIZEOF_FLOAT"><code>SIZEOF_FLOAT</code></a></p>

<p>size of a float</p>
          <dt id="SIZEOF_INT">SIZEOF_INT
          <dd><p><a href="Fiddle.html#SIZEOF_INT"><code>SIZEOF_INT</code></a></p>

<p>size of an int</p>
          <dt id="SIZEOF_INT16_T">SIZEOF_INT16_T
          <dd><p><a href="Fiddle.html#SIZEOF_INT16_T"><code>SIZEOF_INT16_T</code></a></p>

<p>size of a int16_t</p>
          <dt id="SIZEOF_INT32_T">SIZEOF_INT32_T
          <dd><p><a href="Fiddle.html#SIZEOF_INT32_T"><code>SIZEOF_INT32_T</code></a></p>

<p>size of a int32_t</p>
          <dt id="SIZEOF_INT64_T">SIZEOF_INT64_T
          <dd><p><a href="Fiddle.html#SIZEOF_INT64_T"><code>SIZEOF_INT64_T</code></a></p>

<p>size of a int64_t</p>
          <dt id="SIZEOF_INT8_T">SIZEOF_INT8_T
          <dd><p><a href="Fiddle.html#SIZEOF_INT8_T"><code>SIZEOF_INT8_T</code></a></p>

<p>size of a int8_t</p>
          <dt id="SIZEOF_INTPTR_T">SIZEOF_INTPTR_T
          <dd><p><a href="Fiddle.html#SIZEOF_INTPTR_T"><code>SIZEOF_INTPTR_T</code></a></p>

<p>size of a intptr_t</p>
          <dt id="SIZEOF_LONG">SIZEOF_LONG
          <dd><p><a href="Fiddle.html#SIZEOF_LONG"><code>SIZEOF_LONG</code></a></p>

<p>size of a long</p>
          <dt id="SIZEOF_LONG_LONG">SIZEOF_LONG_LONG
          <dd><p><a href="Fiddle.html#SIZEOF_LONG_LONG"><code>SIZEOF_LONG_LONG</code></a></p>

<p>size of a long long</p>
          <dt id="SIZEOF_PTRDIFF_T">SIZEOF_PTRDIFF_T
          <dd><p><a href="Fiddle.html#SIZEOF_PTRDIFF_T"><code>SIZEOF_PTRDIFF_T</code></a></p>

<p>size of a ptrdiff_t</p>
          <dt id="SIZEOF_SHORT">SIZEOF_SHORT
          <dd><p><a href="Fiddle.html#SIZEOF_SHORT"><code>SIZEOF_SHORT</code></a></p>

<p>size of a short</p>
          <dt id="SIZEOF_SIZE_T">SIZEOF_SIZE_T
          <dd><p><a href="Fiddle.html#SIZEOF_SIZE_T"><code>SIZEOF_SIZE_T</code></a></p>

<p>size of a size_t</p>
          <dt id="SIZEOF_SSIZE_T">SIZEOF_SSIZE_T
          <dd><p><a href="Fiddle.html#SIZEOF_SSIZE_T"><code>SIZEOF_SSIZE_T</code></a></p>

<p>size of a ssize_t</p>
          <dt id="SIZEOF_UCHAR">SIZEOF_UCHAR
          <dd><p><a href="Fiddle.html#SIZEOF_UCHAR"><code>SIZEOF_UCHAR</code></a></p>

<p>size of a unsigned char</p>
          <dt id="SIZEOF_UINT">SIZEOF_UINT
          <dd><p><a href="Fiddle.html#SIZEOF_UINT"><code>SIZEOF_UINT</code></a></p>

<p>size of an unsigned int</p>
          <dt id="SIZEOF_UINT16_T">SIZEOF_UINT16_T
          <dd><p><a href="Fiddle.html#SIZEOF_UINT16_T"><code>SIZEOF_UINT16_T</code></a></p>

<p>size of a uint16_t</p>
          <dt id="SIZEOF_UINT32_T">SIZEOF_UINT32_T
          <dd><p><a href="Fiddle.html#SIZEOF_UINT32_T"><code>SIZEOF_UINT32_T</code></a></p>

<p>size of a uint32_t</p>
          <dt id="SIZEOF_UINT64_T">SIZEOF_UINT64_T
          <dd><p><a href="Fiddle.html#SIZEOF_UINT64_T"><code>SIZEOF_UINT64_T</code></a></p>

<p>size of a uint64_t</p>
          <dt id="SIZEOF_UINT8_T">SIZEOF_UINT8_T
          <dd><p><a href="Fiddle.html#SIZEOF_UINT8_T"><code>SIZEOF_UINT8_T</code></a></p>

<p>size of a uint8_t</p>
          <dt id="SIZEOF_UINTPTR_T">SIZEOF_UINTPTR_T
          <dd><p><a href="Fiddle.html#SIZEOF_UINTPTR_T"><code>SIZEOF_UINTPTR_T</code></a></p>

<p>size of a uintptr_t</p>
          <dt id="SIZEOF_ULONG">SIZEOF_ULONG
          <dd><p><a href="Fiddle.html#SIZEOF_ULONG"><code>SIZEOF_ULONG</code></a></p>

<p>size of a unsigned long</p>
          <dt id="SIZEOF_ULONG_LONG">SIZEOF_ULONG_LONG
          <dd><p><a href="Fiddle.html#SIZEOF_ULONG_LONG"><code>SIZEOF_ULONG_LONG</code></a></p>

<p>size of a unsigned long long</p>
          <dt id="SIZEOF_USHORT">SIZEOF_USHORT
          <dd><p><a href="Fiddle.html#SIZEOF_USHORT"><code>SIZEOF_USHORT</code></a></p>

<p>size of a unsigned short</p>
          <dt id="SIZEOF_VOIDP">SIZEOF_VOIDP
          <dd><p><a href="Fiddle.html#SIZEOF_VOIDP"><code>SIZEOF_VOIDP</code></a></p>

<p>size of a void*</p>
          <dt id="VERSION">VERSION
          <dd>
          <dt id="WINDOWS">WINDOWS
          <dd><p>Returns a boolean regarding whether the host is WIN32</p>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-dlopen" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dlopen(library) &rarr; Fiddle::Handle
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new handler that opens <code>library</code>, and returns an instance of <a href="Fiddle/Handle.html"><code>Fiddle::Handle</code></a>.</p>

<p>If <code>nil</code> is given for the <code>library</code>, Fiddle::Handle::DEFAULT is used, which is the equivalent to RTLD_DEFAULT. See <code>man 3 dlopen</code> for more.</p>

<pre class="ruby"><span class="ruby-identifier">lib</span> = <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">dlopen</span>(<span class="ruby-keyword">nil</span>)
</pre>

<p>The default is dependent on OS, and provide a handle for all libraries already loaded. For example, in most cases you can use this to access <code>libc</code> functions, or ruby functions like <code>rb_str_new</code>.</p>

<p>See <a href="Fiddle/Handle.html#method-c-new"><code>Fiddle::Handle.new</code></a> for more.</p>

                              <div class="method-source-code" id="dlopen-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dlopen</span> <span class="ruby-identifier">library</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-constant">Fiddle</span><span class="ruby-operator">::</span><span class="ruby-constant">Handle</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">library</span>)
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">DLError</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">error</span>
    <span class="ruby-keyword">case</span> <span class="ruby-constant">RUBY_PLATFORM</span>
    <span class="ruby-keyword">when</span> <span class="ruby-regexp">/linux/</span>
      <span class="ruby-keyword">case</span> <span class="ruby-identifier">error</span>.<span class="ruby-identifier">message</span>
      <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A(\/.+?): (?:invalid ELF header|file too short)/</span>
        <span class="ruby-comment"># This may be a linker script:</span>
        <span class="ruby-comment"># https://sourceware.org/binutils/docs/ld.html#Scripts</span>
        <span class="ruby-identifier">path</span> = <span class="ruby-node">$1</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">raise</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">raise</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">input</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">input</span>.<span class="ruby-identifier">each_line</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">case</span> <span class="ruby-identifier">line</span>
        <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A\s*(?:INPUT|GROUP)\s*\(\s*([^\s,\)]+)/</span>
          <span class="ruby-comment"># TODO: Should we support multiple files?</span>
          <span class="ruby-keyword">return</span> <span class="ruby-identifier">dlopen</span>(<span class="ruby-node">$1</span>)
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Not found</span>
    <span class="ruby-identifier">raise</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-dlunwrap" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dlunwrap(addr)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the Ruby object stored at the memory address <code>addr</code></p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
<span class="ruby-comment"># =&gt; #&lt;Object:0x0000000107c7d870&gt;</span>
<span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">dlwrap</span>(<span class="ruby-identifier">x</span>)
<span class="ruby-comment"># =&gt; 4425504880</span>
<span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">dlunwrap</span>(<span class="ruby-identifier">_</span>)
<span class="ruby-comment"># =&gt; #&lt;Object:0x0000000107c7d870&gt;</span>
</pre>

                              <div class="method-source-code" id="dlunwrap-source">
            <pre>VALUE
rb_fiddle_ptr2value(VALUE self, VALUE addr)
{
    return (VALUE)NUM2PTR(addr);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-dlwrap" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dlwrap(val)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the memory address of the Ruby object stored at <code>val</code></p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
<span class="ruby-comment"># =&gt; #&lt;Object:0x0000000107c7d870&gt;</span>
<span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">dlwrap</span>(<span class="ruby-identifier">x</span>)
<span class="ruby-comment"># =&gt; 4425504880</span>
</pre>

<p>In the case <code>val</code> is not a heap allocated object, this method will return the tagged pointer value.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">dlwrap</span>(<span class="ruby-value">123</span>)
<span class="ruby-comment"># =&gt; 247</span>
</pre>

                              <div class="method-source-code" id="dlwrap-source">
            <pre>static VALUE
rb_fiddle_value2ptr(VALUE self, VALUE val)
{
    return PTR2NUM((void*)val);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-free" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          free(addr)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Free the memory at address <code>addr</code></p>

                              <div class="method-source-code" id="free-source">
            <pre>VALUE
rb_fiddle_free(VALUE self, VALUE addr)
{
    void *ptr = NUM2PTR(addr);

    ruby_xfree(ptr);
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-last_error" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">last_error</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the last <code>Error</code> of the current executing <code>Thread</code> or nil if none</p>

                              <div class="method-source-code" id="last_error-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">last_error</span>
  <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:__FIDDLE_LAST_ERROR__</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-last_error-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">last_error=</span><span
                                class="method-args">(error)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the last <code>Error</code> of the current executing <code>Thread</code> to <code>error</code></p>

                              <div class="method-source-code" id="last_error-3D-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle.rb, line 40</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">last_error=</span> <span class="ruby-identifier">error</span>
  <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:__DL2_LAST_ERROR__</span>] = <span class="ruby-identifier">error</span>
  <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:__FIDDLE_LAST_ERROR__</span>] = <span class="ruby-identifier">error</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-malloc" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          malloc(size)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Allocate <code>size</code> bytes of memory and return the integer memory address for the allocated memory.</p>

                              <div class="method-source-code" id="malloc-source">
            <pre>static VALUE
rb_fiddle_malloc(VALUE self, VALUE size)
{
    void *ptr;
    ptr = (void*)ruby_xcalloc(1, NUM2SIZET(size));
    return PTR2NUM(ptr);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-realloc" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          realloc(addr, size)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Change the size of the memory allocated at the memory location <code>addr</code> to <code>size</code> bytes.  Returns the memory address of the reallocated memory, which may be different than the address passed in.</p>

                              <div class="method-source-code" id="realloc-source">
            <pre>static VALUE
rb_fiddle_realloc(VALUE self, VALUE addr, VALUE size)
{
    void *ptr = NUM2PTR(addr);

    ptr = (void*)ruby_xrealloc(ptr, NUM2SIZET(size));
    return PTR2NUM(ptr);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-win32_last_error" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">win32_last_error</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the last win32 <code>Error</code> of the current executing <code>Thread</code> or nil if none</p>

                              <div class="method-source-code" id="win32_last_error-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle.rb, line 12</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">win32_last_error</span>
  <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:__FIDDLE_WIN32_LAST_ERROR__</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-win32_last_error-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">win32_last_error=</span><span
                                class="method-args">(error)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the last win32 <code>Error</code> of the current executing <code>Thread</code> to <code>error</code></p>

                              <div class="method-source-code" id="win32_last_error-3D-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle.rb, line 17</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">win32_last_error=</span> <span class="ruby-identifier">error</span>
  <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:__FIDDLE_WIN32_LAST_ERROR__</span>] = <span class="ruby-identifier">error</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-win32_last_socket_error" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">win32_last_socket_error</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the last win32 socket <code>Error</code> of the current executing <code>Thread</code> or nil if none</p>

                              <div class="method-source-code" id="win32_last_socket_error-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle.rb, line 23</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">win32_last_socket_error</span>
  <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:__FIDDLE_WIN32_LAST_SOCKET_ERROR__</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-win32_last_socket_error-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">win32_last_socket_error=</span><span
                                class="method-args">(error)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the last win32 socket <code>Error</code> of the current executing <code>Thread</code> to <code>error</code></p>

                              <div class="method-source-code" id="win32_last_socket_error-3D-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle.rb, line 29</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">win32_last_socket_error=</span> <span class="ruby-identifier">error</span>
  <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:__FIDDLE_WIN32_LAST_SOCKET_ERROR__</span>] = <span class="ruby-identifier">error</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-dlopen" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dlopen(library) &rarr; Fiddle::Handle
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new handler that opens <code>library</code>, and returns an instance of <a href="Fiddle/Handle.html"><code>Fiddle::Handle</code></a>.</p>

<p>If <code>nil</code> is given for the <code>library</code>, Fiddle::Handle::DEFAULT is used, which is the equivalent to RTLD_DEFAULT. See <code>man 3 dlopen</code> for more.</p>

<pre class="ruby"><span class="ruby-identifier">lib</span> = <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">dlopen</span>(<span class="ruby-keyword">nil</span>)
</pre>

<p>The default is dependent on OS, and provide a handle for all libraries already loaded. For example, in most cases you can use this to access <code>libc</code> functions, or ruby functions like <code>rb_str_new</code>.</p>

<p>See <a href="Fiddle/Handle.html#method-c-new"><code>Fiddle::Handle.new</code></a> for more.</p>

                              <div class="method-source-code" id="dlopen-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dlopen</span> <span class="ruby-identifier">library</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-constant">Fiddle</span><span class="ruby-operator">::</span><span class="ruby-constant">Handle</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">library</span>)
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">DLError</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">error</span>
    <span class="ruby-keyword">case</span> <span class="ruby-constant">RUBY_PLATFORM</span>
    <span class="ruby-keyword">when</span> <span class="ruby-regexp">/linux/</span>
      <span class="ruby-keyword">case</span> <span class="ruby-identifier">error</span>.<span class="ruby-identifier">message</span>
      <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A(\/.+?): (?:invalid ELF header|file too short)/</span>
        <span class="ruby-comment"># This may be a linker script:</span>
        <span class="ruby-comment"># https://sourceware.org/binutils/docs/ld.html#Scripts</span>
        <span class="ruby-identifier">path</span> = <span class="ruby-node">$1</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">raise</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">raise</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">input</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">input</span>.<span class="ruby-identifier">each_line</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
        <span class="ruby-keyword">case</span> <span class="ruby-identifier">line</span>
        <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A\s*(?:INPUT|GROUP)\s*\(\s*([^\s,\)]+)/</span>
          <span class="ruby-comment"># TODO: Should we support multiple files?</span>
          <span class="ruby-keyword">return</span> <span class="ruby-identifier">dlopen</span>(<span class="ruby-node">$1</span>)
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Not found</span>
    <span class="ruby-identifier">raise</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

